// ex7_13_7.cpp :C7:7.7:arrfun3.cpp -- array functions and const
#include <iostream>
const int Max = 5;

double *fill_array(double *begin, double *end, int limit);
void show_array(const double ar[],  double *limit);
void revalue(double r, double ar[], double *limit);
int main(void)
{
	using namespace std;
	double properties[Max];
	double *begin = properties;
	double *end = properties + Max;

	double *size = fill_array(begin, end, Max);
	if (size != nullptr)
	{
		cout << "Enter revaluation factor: ";
		double factor;
		while (!(cin >> factor))    // bad input
	    {
			cin.clear();
			while (cin.get() != '\n')
				continue;
			cout << "Bad input; Please enter a nubmer: ";
		}									
		revalue(factor, properties, size);
		show_array(properties, size);
	}
	cout << "Done.\n";
	cin.get();
	cin.get();
	return 0;
}

double *fill_array(double *begin, double *end, int limit)
{
	using namespace std;
	double temp;

	int i,count;
	for (i = 0; i < limit; i++)
	{
		cout << "Enter value #" << (i+1) << ": ";
		cin >> temp;
		if (!cin)
		{
			cin.clear();
			while (cin.get() != '\n')
				continue;
			cout << "Bad input; input process terminated.\n";
			break;
		}
		else if (temp < 0)    // signal to terminated
			break;
		// current pointer not equal to end pointer,
		// store value to array
		if((begin + i) != end)
			*(begin + i) = temp; 
	}
	count = i;
	return begin + count;
}

void show_array(const double ar[], double *limit)
{
	using namespace std;
	//double *ptr = ar;
	for (int i = 0; (ar + i) != limit; i++)
	{
		cout << "Property #" << (i + 1) << ": $";
		cout << ar[i] << endl;
	}
}
// multiplies each element of ar[] by r
void revalue(double r, double ar[], double *limit)
{
	//double *ptr = ar;
	for (int i = 0; (ar + i) != limit; i++)
		ar[i] *= r;
}
